package iss.team2.lams.dao;



import iss.team2.lams.model.LeaveType;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import org.hibernate.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

public class LeaveTypeDAOImpl extends LDAO implements LeaveTypeDao, RowMapper<LeaveType>
{
	@Autowired
	DataSource datasource;

	public LeaveTypeDAOImpl() 
	{
		table="leave_type";
	}

	@Override
	public void create(LeaveType lt) 
	{
		query="insert into "+table+" values(?,?,?,?)";
		jtempl=new JdbcTemplate(datasource);
		jtempl.update(query,lt.getLeaveCode(),lt.getLeaveType(),lt.getDescription(),lt.getNumOfDay()); 	
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<LeaveType> listLeaveType() 
	{
		query=getSelectQuery();
		jtempl=new JdbcTemplate(datasource);
		return jtempl.query(query,this);
		// TODO Auto-generated method stub
	}

	
	@Override
	public LeaveType update(LeaveType lt) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void delete(String leavecode) 
	{
		query = getDeleteQuery() + " where leaveCode = '" + leavecode + "'";
		jtempl=new JdbcTemplate(datasource);
		jtempl.update(query);
		// TODO Auto-generated method stub
		
	}

	@Override
	public LeaveType mapRow(ResultSet arg0, int arg1) throws SQLException 
	{
		LeaveType lt=new LeaveType();
		lt.setLeaveCode(arg0.getString("leaveCode"));
		lt.setDescription(arg0.getString("description"));
		return lt;
		
		// TODO Auto-generated method stub
	
	}

//	@Override
//	public List<LeaveType> listLeaveType() {
//		// TODO Auto-generated method stub
//		return null;
//	}
	
	


}
